package com.easy;

/**
 * Created by Lxk on 2019/5/13.
 */
public class Solution189 {

    public static void rotate(int[] nums, int k) {
        if(nums == null || nums.length == 0){
            return ;
        }
        if(k<=0){
            return ;
        }
        k = k%nums.length;
        //左半部分转置
        int left = nums.length - k;
        for(int i = 0;i < left/2; i++){
            int temp = nums[left-i-1];
            nums[left-i-1] = nums[i];
            nums[i] = temp;
        }
        //右半部分转置
        for(int i = 0;i < k/2; i++){
            int temp = nums[left+i];
            nums[left+i] = nums[nums.length-i-1];
            nums[nums.length-i-1] = temp;
        }
        //全局转置
        for(int i = 0;i < nums.length/2; i++){
            int temp = nums[nums.length-i-1];
            nums[nums.length-i-1] = nums[i];
            nums[i] = temp;
        }
    }

    public static void main(String[] args) {
//        int[] arr = {1,2,3,4,5,6,7};
        int[] arr = {-1,-100,3,99};
        rotate(arr,2);
        for(int val : arr){
            System.out.print(val);
        }
    }

}
